/** CS2340 Spring 2011 Project
 *  Team: 40 Jiggawatt Hard Driver
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 *
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */

// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString
package edu.gatech.jiggawatt.office.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Represents Patient
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */
public class Patient extends User implements Serializable { // $codepro.audit.disable declareDefaultConstructors
	
    private String pharmacy;
    private String insurance;
    private String allergies;
    private List<Appointment> appointments;
    private List<TreatmentRecord> records;
    

    /**
     * Constructor for Patient.
     * @param id String
     * @param pw String
     * @param firstName String
     * @param lastName String
     */
    public Patient(String id, String pw, String firstName, String lastName) {
    	super(id, pw, firstName, lastName, 1);
    	appointments = new ArrayList<Appointment>();
    	records = new ArrayList<TreatmentRecord>();
    }
    
    /**
     * Comprehensive constructor for patient
     * @param id
     * @param pw
     * @param firstName
     * @param lastName
     * @param age
     * @param gender
     * @param address
     * @param phone
     * @param email
     */
    public Patient(String id, String pw, String firstName, String lastName, int age, int gender, String address, String phone, String email)
    {
    	super(id, pw, firstName, lastName, age, gender, address, phone, email, 1);
    	appointments = new ArrayList<Appointment>();
    	records = new ArrayList<TreatmentRecord>();
    }

    /**
     * sets allergies
     * @param allergies
     */
	public void setAllergies(String allergies) {
		this.allergies = allergies;
	}

	/**
	 * gets allergies
	 * @return allergies
	 */
	public String getAllergies() {
		return allergies;
	}

	/**
	 * sets insurance
	 * @param insurance
	 */
	public void setInsurance(String insurance) {
		this.insurance = insurance;
	}

	/**
	 * gets insurance
	 * @return insurance
	 */
	public String getInsurance() {
		return insurance;
	}

	/**
	 * sets pharmacy
	 * @param pharmacy
	 */
	public void setPharmacy(String pharmacy) {
		this.pharmacy = pharmacy;
	}

	/**
	 * gets pharmacy
	 * @return pharmacy
	 */
	public String getPharmacy() {
		return pharmacy;
	}

	/**
	 * adds appointment
	 * @param app
	 */
	public void addAppointment(Appointment app)
	{
		appointments.add(app);		
		Collections.sort(appointments);
	}
	
	/**
	 * changes appointment
	 * @param oldApp
	 * @param newApp
	 * @return true if success, false otherwise
	 */
	public boolean changeAppointment(Appointment oldApp, Appointment newApp) // $codepro.audit.disable booleanMethodNamingConvention
	{
		if (removeAppointment(oldApp))
		{
			appointments.add(newApp);
			Collections.sort(appointments);
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * gets appointment at index i
	 * @param i index of appointment
	 * @return appointment retrieved
	 */
	public Appointment getAppointment(int i)
	{
		return appointments.get(i);
	}
	
	/**
	 * gets list of appointments
	 * @return list of appointments
	 */
	public List<Appointment> getAppointments()
	{
		return appointments;
	}
	
	/**
	 * removes appointment
	 * @param app
	 * @return true if success, false otherwise
	 */
	public boolean removeAppointment(Appointment app) // $codepro.audit.disable booleanMethodNamingConvention
	{
		return appointments.remove(app);
	}
	
	/**
	 * adds treatment record
	 * @param tr
	 */
	public void addTreatmentRecord(TreatmentRecord tr){
		records.add(tr);
		Collections.sort(records);
	}
	
	/**
	 * changes treatment record
	 * @param oldtr
	 * @param newTr
	 * @return true if success, false otherwise
	 */
	public boolean changeTreatmentRecord(TreatmentRecord oldtr, TreatmentRecord newTr) // $codepro.audit.disable booleanMethodNamingConvention
	{
		if (removeTreatmentRecord(oldtr))
		{
			records.add(newTr);
			Collections.sort(records);
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * gets treatment record
	 * @param date
	 * @param time
	 * @return treatment record retrieved
	 */
	public TreatmentRecord getTreatmentRecord(Date date, Time time)
	{
		for (TreatmentRecord tr : records)
		{
			if (tr.getDate().equals(date) && tr.getTime().equals(time))
			{
				return tr;
			}
		}
		return null;
	}
	
	/**
	 * gets list of treatment records
	 * @return list of treatment records
	 */
	public List<TreatmentRecord> getTreatmentRecords()
	{
		return records;
	}
	
	/**
	 * removes treatment record
	 * @param tr treatment record to remove
	 * @return true if success, false otherwise
	 */
	public boolean removeTreatmentRecord(TreatmentRecord tr) // $codepro.audit.disable booleanMethodNamingConvention
	{
		return records.remove(tr);
	}
}